Module mdlLicense
    Public Function strHDDSrNo() As String
        Dim WMI As Object
        Dim wmiCollection As Object
        Dim wmiMember As Object

        strHDDSrNo = ""

        WMI = GetObject("winmgmts:\\")
        wmiCollection = WMI.InstancesOf("Win32_DiskDrive")

        For Each wmiMember In wmiCollection
            strHDDSrNo = CheckValue(wmiMember.Model)
            Exit For
        Next

        Return Strings.StrReverse(strHDDSrNo)
    End Function

    Private Function CheckValue(ByVal s As Object) As String
        If VarType(s) = vbNull Then s = ""
        s = Trim(s)
        If s = "" Then CheckValue = "Not available" Else CheckValue = s

        Return CheckValue
    End Function

    Private Function strVolumeSrNo() As String
        strVolumeSrNo = ""

        Try
            Dim Buf$ = "", Name$ = "", Flags&, Length&
            Dim Serial As Long

            GetVolumeInformation("C:\", Buf$, 255, Serial, Length, Flags, Name$, 255)
            strVolumeSrNo = Serial

        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of mdlLicense")
        End Try
    End Function

    Public Function GetLocalKey() As String
        Dim s As String, s1 As String, s2 As String
        Dim i As Integer, nVal As Integer

        's = Trim(CStr(strHDDSrNo()))    'HDD Serial Number

        Dim ss As SYSTOOLSLIBRARYLib.HardDriveInfo

        ss = New SYSTOOLSLIBRARYLib.HardDriveInfo
        ss.Initialize(0, "3D52DCF2-B43C-49b4")

        s = ss.SerialNumber            'HDD Serial Number

        If Len(s) < 16 Then
            s1 = Right(s, 16 - Len(s))
            s2 = ""
            For i = 1 To Len(s1)
                nVal = (Val(Mid(s1, i, 1)) + i) Mod 10
                s2 = s2 & Trim(CStr(nVal))
            Next i
            s = s & s2
        End If
        GetLocalKey = s & IIf(s.Length < 16, StrDup(16 - s.Length, "3"), "")

        Return GetLocalKey
    End Function

    Public Function GetLicenseKey() As String
        Dim s As String, sLocalKey As String
        Dim i As Integer, nVal As Integer

        sLocalKey = GetLocalKey()

        s = ""
        For i = sLocalKey.Length To 1 Step -1
            nVal = (9 - Val(Mid(sLocalKey, i, 1)) + i)
            If nVal Mod 2 = 0 And nVal >= 5 And nVal <= 20 Then
                nVal = nVal - 5
            ElseIf nVal Mod 2 > 0 And nVal >= 5 And nVal <= 20 Then
                nVal = nVal - 4
            End If
            s = s & Chr(nVal + 65)
        Next i

        GetLicenseKey = s
        Return GetLicenseKey
    End Function
End Module
